import unittest
import os
from src.cmake_analysis import get_cmake_errors
from src.sup_function import get_test_data_path, normalize_text


class FileTest(unittest.TestCase):

    def test_check_cmake_file_good(self):
        self.assertFalse(len([i_error for i_error in get_cmake_errors(os.path.join(get_test_data_path(),
                                                                                   'cmake_good.log'))]))

    def test_check_cmake_file_not_found(self):
        expected = [('file_not_found', normalize_text('CMake Error at UnitTests/CMakeLists.txt:258 (add_executable): Cannot find source file: C:/Users/c3dlabs/Projects/C3DSolverATS/Source/UnitTests/Journals2d/utest_Bugs_KOMAPS_39182_sketch_2.cpp\n'))]
        actual = [(res[0], normalize_text(res[1])) for res in get_cmake_errors(os.path.join(get_test_data_path(), 'cmake_error_file_not_found.log'))]
        self.assertEqual(expected, actual)

    def test_check_cmake_no_sources(self):
        expected = [('no_sources', normalize_text('CMake Error at Math/CMakeLists.txt:2702 (add_library): No SOURCES given to target: math\n'))]
        actual = [(res[0], normalize_text(res[1])) for res in get_cmake_errors(os.path.join(get_test_data_path(), 'cmake_error_no_sources.log'))]
        self.assertEqual(expected, actual)

    def test_check_cmake_linker_language(self):
        expected = [('linker_language', normalize_text('CMake Error: CMake can not determine linker language for target: unit_tests\n'))]
        actual = [(res[0], normalize_text(res[1])) for res in get_cmake_errors(os.path.join(get_test_data_path(), 'cmake_error_linker_language.log'))]
        self.assertEqual(expected, actual)


if __name__ == '__main__':
    unittest.main()
